import { db } from "@src/db"
import { eq } from 'drizzle-orm';
import { users } from '@src/db/schema/users';


async function getUser({ username }: { username: string }) {
  const [user] = await db.select().from(users).where(eq(users.name, username));
  return user
}

async function getAllUser() {
  const userlist = await db.select().from(users);
  return userlist
}


async function register(params: { name: string; password: string; email: string; salt: string; role_id: number }) {
  const result = await db.insert(users).values(params).$returningId();
  return result[0]; // 返回插入的用户信息
}


export default {
  getUser,
  register,
  getAllUser,
}
